package homework10_String;

import java.util.Scanner;
import java.util.StringJoiner;

/**
 * @author admin
 * @version 1.0
 * @date 2024-04-01 17:26
 */

public class Test01 {
    public static void main(String[] args) {
        System.out.println("请输入一串字符串(长度不大于9，且全为数字):");
        Scanner sc = new Scanner(System.in);
        String str;
        while (true) {
            str = sc.nextLine();
            boolean flag = checkStr(str);
            if (flag) {
                break;
            } else {
                System.out.println("输入字符串格式错误，请重新输入!");
            }
        }
        StringJoiner sb = new StringJoiner(" ");
//        for (int i = 0; i < str.length(); i++) {
//        int number=str.charAt(i)-48;
//        sb.add(changeluoma1(number));
//        }
//        System.out.println("转换成罗马数字为:"+sb);
        for (int i = 0; i < str.length(); i++) {
            char number = str.charAt(i);
            String result = changeluoma2(number);
            sb.add(result);
        }
        System.out.println(sb);
    }

    public static boolean checkStr(String str) {
        if (str.length() > 9) {
            return false;
        }
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c < '0' || c > '9') {
                return false;
            }
        }
        return true;
    }

    public static String changeluoma1(int number) {
        String[] arr = {" ", "Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", "Ⅶ", "Ⅷ", "Ⅸ"};
        return arr[number];
    }

    public static String changeluoma2(char number) {
        String str;
        switch (number) {
            case '0':
                str = "";
                break;
            case '1':
                str = "Ⅰ";
                break;
            case '2':
                str = "Ⅱ";
                break;
            case '3':
                str = "Ⅲ";
                break;
            case '4':
                str = "Ⅳ";
                break;
            case '5':
                str = "Ⅴ";
                break;
            case '6':
                str = "Ⅵ";
                break;
            case '7':
                str = "Ⅶ";
                break;
            case '8':
                str = "Ⅷ";
                break;
            case '9':
                str = "Ⅸ";
                break;
            default:
                str = "";
                break;
        }
        return str;
    }
}
